<?php

declare(strict_types=1);

namespace App\AdminApi\Module\Admin\Validate;

use App\AdminApi\Module\Admin\Enums\MenuEnums;
use Zms\Constants\Database;
use Zms\Validate\ValidateAbstract;

/**
 * 后台菜单验证器
 */
class MenuValidate extends ValidateAbstract
{
    public function rules(): array
    {
        return [
            ['id', 'required', 'error' => '数据异常，请刷新重试', 'on' => ['updated']],
            ['id', 'number', 'error' => '数据异常，请刷新重试', 'on' => ['updated']],

            ['name', 'required', 'error' => '请输入{label}', 'on' => ['created', 'updated']],
            ['name', 'string', 'max' => 10, 'error' => '{label}错误', 'on' => ['created', 'updated']],

            ['pid', 'required', 'error' => '数据异常，请刷新重试', 'on' => ['created']],
            ['pid', 'number', 'error' => '数据异常，请刷新重试', 'on' => ['created']],

            ['path', 'string', 'error' => '{label}错误', 'max' => 50, 'on' => ['created', 'updated']],

            ['sort', 'number', 'min' => Database::INT_MIN, 'max' => Database::INT_MAX, 'precision' => 0, 'on' => ['created', 'updated']],

            ['icon', 'string', 'max' => 30, 'maxError' => '{label}错误', 'on' => ['created', 'updated']],

            ['is_nav', 'in', 'enums' => MenuEnums::Values(MenuEnums::TAG['IS_NAV']), 'on' => ['created', 'updated']],

            ['node', 'list', 'error' => '{label}选择错误', 'on' => ['created', 'updated']],
        ];
    }


    public function labels(): array
    {
        return [
            'name' => '菜单名称',
            'group' => '菜单上级',
            'path' => '菜单路由',
            'sort' => '菜单排序',
            'icon' => '菜单图标',
            'is_nav' => '菜单显示',
            'node' => '节点权限'
        ];
    }
}